package day3;

public class ch3 {

    //48
    public void rotate(int[][] matrix) {
        int m = matrix.length;
        int n = matrix[0].length;

        int left = 0;
        int rigrh = m-1;
        while (left<rigrh){
            for (int i = 0; i < n; i++) {
                int num = matrix[left][i];
                matrix[left][i] =  matrix[rigrh][i];
                matrix[rigrh][i] = num;
            }
            left++;
            rigrh--;
        }


        for (int i = 0; i < m; i++) {
            for (int j = 0; j < i; j++) {
                int num = matrix[i][j];
                matrix[i][j] =  matrix[j][i];
                matrix[j][i] = num;
            }

        }
    }

    //240
    public boolean searchMatrix(int[][] matrix, int target) {

        return fun(matrix,0,matrix[0].length-1,target);



    }

    public boolean fun(int[][] matrix,int i,int j,int target){
        int m = matrix.length;
        int n = matrix[0].length;

        if(i<0||i>=m) return false;
        if(j<0||j>=n) return false;

        if(matrix[i][j]==target){
            return true;
        } else if (matrix[i][j]>target) {
            return fun(matrix,i,j-1,target);
        }else {
            return fun(matrix,i+1,j,target);
        }


    }


    public static void main(String[] args) {

    }
}
